package com.onepiece.OJ.controller;

import com.onepiece.OJ.config.R;
import com.onepiece.OJ.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;


@Controller
@ResponseBody
public class UploadController {


    @Autowired
    private UploadService uploadService;

    /**
     * 图片上传
     */
    @PostMapping(value = "/uploadImg")
    public R<String> uploadImg(@RequestPart("file") MultipartFile file) {
        String url = uploadService.uploadImg(file);
        return R.success(url);
    }

    /**
     * 文章上传
     */
    @PostMapping(value = "/uploadArticle")
    public R<String> uploadMD(@RequestPart("file") MultipartFile file) {
        String url =uploadService.uploadMD(file);
        return R.success(url);
    }
}
